package cn.edu.seig.textbook.mapper;

import cn.edu.seig.textbook.domain.pojo.Textbooks;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author day
 * @since 2024-11-07
 */
@Mapper
public interface TextbooksMapper extends BaseMapper<Textbooks> {
    // 查询所有教材
    @Select("SELECT * FROM tb_textbooks")
    List<Textbooks> getAllTextbooks();

    // 根据教材ID查询教材
    @Select("SELECT * FROM tb_textbooks WHERE textbook_id = #{textbookId}")
    Textbooks getTextbookById(int textbookId);

    @Select("SELECT * FROM tb_textbooks WHERE book_name LIKE CONCAT('%', #{bookName}, '%')")
    List<Textbooks> getTextbooksByBookName(@Param("bookName") String bookName);

    // 根据课程名称模糊查询教材
    @Select("SELECT * FROM tb_textbooks WHERE course_name LIKE CONCAT('%', #{courseName}, '%')")
    List<Textbooks> getTextbooksByCourseName(@Param("courseName") String courseName);

    // 添加教材
    @Insert("INSERT INTO tb_textbooks (course_name, book_name, author, isbn, price, publish_date, version) " +
            "VALUES (#{courseName}, #{bookName}, #{author}, #{isbn}, #{price}, #{publishDate}, #{version})")
    @Options(useGeneratedKeys = true, keyProperty = "textbookId")
    int addTextbook(Textbooks textbook);

}
